{% extends "base.html" %}

{% block title %}{{ market.name }} - 超市详情{% endblock %}

{% block content %}
<div class="row mb-4">
    <div class="col-12 d-flex justify-content-between align-items-center">
        <h2 class="mb-0"><i class="fas fa-store me-2"></i>超市详情</h2>
        <div>
            <a href="{{ url_for('supermarket.list') }}" class="btn btn-secondary">
                <i class="fas fa-arrow-left me-1"></i>返回列表
            </a>
            <a href="{{ url_for('supermarket.edit', market_id=market.market_id) }}" class="btn btn-primary ms-2">
                <i class="fas fa-edit me-1"></i>编辑
            </a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-4 mb-4">
        <div class="card shadow-sm h-100">
            <div class="card-body text-center">
                {% if market.image_url %}
                <img src="{{ market.image_url.strip('@') if market.image_url.startswith('@') else market.image_url }}" class="img-fluid rounded mb-3" alt="{{ market.name }}" style="max-height: 150px;">
                {% else %}
                <div class="bg-light d-flex justify-content-center align-items-center mb-3" style="height: 150px;">
                    <i class="fas fa-store fa-5x text-muted"></i>
                </div>
                {% endif %}
                
                <h3 class="mb-2">{{ market.name }}</h3>
                <div class="mb-3">
                    <span class="badge bg-{% if market.status == 1 %}success{% else %}secondary{% endif %} mb-2">
                        {% if market.status == 1 %}营业中{% else %}暂停营业{% endif %}
                    </span>
                </div>
                
                <div class="btn-group w-100">
                    <a href="{{ url_for('supermarket.toggle_status', market_id=market.market_id) }}" class="btn btn-{% if market.status == 1 %}warning{% else %}success{% endif %}">
                        <i class="fas {% if market.status == 1 %}fa-eye-slash{% else %}fa-eye{% endif %} me-1"></i>
                        {% if market.status == 1 %}暂停营业{% else %}恢复营业{% endif %}
                    </a>
                    <a href="{{ url_for('supermarket.delete', market_id=market.market_id) }}" class="btn btn-danger btn-delete">
                        <i class="fas fa-trash me-1"></i>删除
                    </a>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-md-8">
        <div class="card shadow-sm mb-4">
            <div class="card-header bg-light">
                <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>基本信息</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">超市编号</h6>
                        <p>{{ market.market_id }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">联系电话</h6>
                        <p>{{ market.phone or '未设置' }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">地址</h6>
                        <p>{{ market.address or '未设置' }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">营业时间</h6>
                        <p>{{ market.business_hours or '未设置' }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">盲盒数量</h6>
                        <p>{{ boxes_count }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">订单数量</h6>
                        <p>{{ orders_count }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">创建时间</h6>
                        <p>{{ market.create_time.strftime('%Y-%m-%d %H:%M:%S') if market.create_time else '未知' }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">更新时间</h6>
                        <p>{{ market.update_time.strftime('%Y-%m-%d %H:%M:%S') if market.update_time else '未知' }}</p>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="card shadow-sm">
            <div class="card-header bg-light">
                <h5 class="mb-0"><i class="fas fa-align-left me-2"></i>超市描述</h5>
            </div>
            <div class="card-body">
                {% if market.description %}
                <p class="mb-0">{{ market.description }}</p>
                {% else %}
                <p class="text-muted mb-0">暂无描述</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 该超市下的盲盒列表 -->
<div class="row mt-4">
    <div class="col-12">
        <div class="card shadow-sm">
            <div class="card-header bg-light d-flex justify-content-between align-items-center">
                <h5 class="mb-0"><i class="fas fa-box me-2"></i>该超市的盲盒列表</h5>
                <a href="{{ url_for('blind_box.add') }}?market_id={{ market.market_id }}" class="btn btn-sm btn-primary">
                    <i class="fas fa-plus-circle me-1"></i>为该超市添加盲盒
                </a>
            </div>
            <div class="card-body">
                {% if blind_boxes %}
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th scope="col">#</th>
                                <th scope="col">盲盒名称</th>
                                <th scope="col">分类</th>
                                <th scope="col">价格</th>
                                <th scope="col">库存</th>
                                <th scope="col">状态</th>
                                <th scope="col">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for box in blind_boxes %}
                            <tr>
                                <td>{{ box.box_id }}</td>
                                <td>{{ box.name }}</td>
                                <td>{{ box.category }}</td>
                                <td>
                                    <span class="text-danger">¥{{ box.discount_price }}</span>
                                    <br>
                                    <small class="text-muted text-decoration-line-through">¥{{ box.original_price }}</small>
                                </td>
                                <td>
                                    {% if box.stock == 0 %}
                                    <span class="badge bg-danger">缺货</span>
                                    {% elif box.stock < 10 %}
                                    <span class="badge bg-warning text-dark">低库存({{ box.stock }})</span>
                                    {% else %}
                                    {{ box.stock }}
                                    {% endif %}
                                </td>
                                <td>
                                    {% if box.status == 1 %}
                                    <span class="badge bg-success">上架</span>
                                    {% else %}
                                    <span class="badge bg-secondary">下架</span>
                                    {% endif %}
                                </td>
                                <td>
                                    <div class="btn-group">
                                        <a href="{{ url_for('blind_box.detail', box_id=box.box_id) }}" class="btn btn-sm btn-info">
                                            <i class="fas fa-info-circle"></i>
                                        </a>
                                        <a href="{{ url_for('blind_box.edit', box_id=box.box_id) }}" class="btn btn-sm btn-primary">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {% else %}
                <div class="text-center py-4 text-muted">
                    <i class="fas fa-box fa-3x mb-3"></i>
                    <p>该超市下暂无盲盒数据</p>
                    <a href="{{ url_for('blind_box.add') }}?market_id={{ market.market_id }}" class="btn btn-primary btn-sm">
                        <i class="fas fa-plus-circle me-1"></i>添加盲盒
                    </a>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
